home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / devel / vbcc-ppc-src / ar / contents.c < prev    next >
C/C++ Source or Header  |  1999-01-01  |  3KB  |  116 lines

  1. /* $VER: ar contents.c V0.1 (31.01.98)
  2.  *
  3.  * This file is part of ar, a portable archive maintanance
  4.  * utility for normal and BSD-style archives.
  5.  * Copyright (c) 1999  Frank Wille
  6.  *
  7.  * ar is freeware and part of the portable and retargetable ANSI C
  8.  * compiler vbcc, copyright (c) 1995-99 by Volker Barthelmann.
  9.  * ar may be freely redistributed as long as no modifications are
  10.  * made and nothing is charged for it. Non-commercial usage is allowed
  11.  * without any restrictions.
  12.  * EVERY PRODUCT OR PROGRAM DERIVED DIRECTLY FROM MY SOURCE MAY NOT BE
  13.  * SOLD COMMERCIALLY WITHOUT PERMISSION FROM THE AUTHOR.
  14.  *
  15.  *
  16.  * v0.1  (31.01.99) phx
  17.  *       First working version, which only supports 'q' (quick append)
  18.  *       and 't' (table of contents), reads and writes normals and
  19.  *       BSD-style archives. Symbol table will not be created!
  20.  * v0.0  (29.01.99) phx
  21.  *       File created.
  22.  */
  23.  
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include "ar.h"
  27. #include "archive.h"
  28. #include "errors.h"
  29.  
  30.  
  31. static bool print_contents(struct Args *,struct Archive *,char *);
  32.  
  33.  
  34.  
  35. void ar_contents(struct Args *args)
  36. {
  37.   struct Archive *ar;
  38.   uint32 i;
  39.  
  40.   if (ar = ar_read(args->arname)) {
  41.     if (args->filecnt) {
  42.       for (i=0; i<args->filecnt; i++)
  43.         if (!print_contents(args,ar,args->files[i]))
  44.           error(ENOTFOUND,args->files[i]);
  45.     }
  46.     else
  47.       print_contents(args,ar,NULL);
  48.   }
  49. }
  50.  
  51.  
  52. #ifdef AMIGA
  53. static char *genmode(char *s,uint16 mode)
  54. {
  55.   if (mode & 4)
  56.     *s++ = 'r';
  57.   else
  58.     *s++ = '-';
  59.   if (mode & 2)
  60.     *s++ = 'w';
  61.   else
  62.     *s++ = '-';
  63.   if (mode & 1)
  64.     *s++ = 'x';
  65.   else
  66.     *s++ = '-';
  67.   return (s);
  68. }
  69.  
  70. static void modestr(char *s,uint16 mode)
  71. /* create a unix-style permission string */
  72. /* @@@ very simple implementation... */
  73. {
  74.   s = genmode(s,(mode>>6)&7);
  75.   s = genmode(s,(mode>>3)&7);
  76.   s = genmode(s,mode&7);
  77.   *s = '\0';
  78. }
  79. #endif
  80.  
  81.  
  82. static bool print_contents(struct Args *args,struct Archive *ar,char *name)
  83. {
  84.   struct ArObject *obj = (struct ArObject *)ar->l.first;
  85.   struct ArObject *next;
  86.   bool found = FALSE;
  87.  
  88.   while (next = (struct ArObject *)obj->n.next) {
  89.     if (name)
  90.       if (strcmp(obj->name,name))
  91.         goto nextobj;
  92.     found = TRUE;
  93.  
  94.     if (args->modifier & AR_VERBOSE) {
  95.       struct tm *tp;
  96.       char buf[32];
  97.  
  98. #ifdef AMIGA
  99.       modestr(buf,obj->mode);
  100. #else
  101.       strmode((mode_t)obj->mode,buf);
  102. #endif
  103.       printf("%s %6u/%-6u %8lu ",buf,(unsigned)obj->uid,
  104.              (unsigned)obj->gid,obj->size);
  105.       tp = localtime(&obj->time);
  106.       strftime(buf,sizeof(buf),"%b %e %H:%M %Y",tp);
  107.       printf("%s %s\n",buf,obj->name);
  108.     }
  109.     else
  110.       printf("%s\n",obj->name);
  111. nextobj:
  112.     obj = next;
  113.   }
  114.   return (found);
  115. }
  116.